.TH std::multimap::begin, 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::multimap::begin, \- std::multimap::begin,

.SH Synopsis

   iterator begin();                       \fB(1)\fP (noexcept since C++11)
   const_iterator begin() const;           \fB(2)\fP (noexcept since C++11)
   const_iterator cbegin() const noexcept; \fB(3)\fP \fI(since C++11)\fP

   Returns an iterator to the first element of the multimap.

   If the multimap is empty, the returned iterator will be equal to end().

   range-begin-end.svg

.SH Parameters

   \fI(none)\fP

.SH Return value

   Iterator to the first element.

.SH Complexity

   Constant.

.SH Notes

   libc++ backports cbegin() to C++98 mode.

.SH Example


// Run this code

 #include <algorithm>
 #include <cassert>
 #include <cstddef>
 #include <iostream>
 #include <map>
 #include <string>

 int main()
 {
     auto show_node = [](const auto& node, char ending = '\\n')
     {
         std::cout << "{ " << node.first << ", " << node.second << " }" << ending;
     };

     std::multimap<std::size_t, std::string> mmap;
     assert(mmap.begin() == mmap.end());   // OK
     assert(mmap.cbegin() == mmap.cend()); // OK

     mmap.insert({ sizeof(long), "LONG" });
     show_node(*(mmap.cbegin()));
     assert(mmap.begin() != mmap.end());   // OK
     assert(mmap.cbegin() != mmap.cend()); // OK
     mmap.begin()->second = "long";
     show_node(*(mmap.cbegin()));

     mmap.insert({ sizeof(int), "int" });
     show_node(*mmap.cbegin());

     mmap.insert({ sizeof(short), "short" });
     show_node(*mmap.cbegin());

     mmap.insert({ sizeof(char), "char" });
     show_node(*mmap.cbegin());

     mmap.insert({{ sizeof(float), "float" }, { sizeof(double), "double"}});

     std::cout << "mmap = { ";
     std::for_each(mmap.cbegin(), mmap.cend(), [&](const auto& n) { show_node(n, ' '); });
     std::cout << "};\\n";
 }

.SH Possible output:

 { 8, LONG }
 { 8, long }
 { 4, int }
 { 2, short }
 { 1, char }
 mmap = { { 1, char } { 2, short } { 4, int } { 4, float } { 8, long } { 8, double } };

.SH See also

   end     returns an iterator to the end
   cend    \fI(public member function)\fP
   \fI(C++11)\fP
   begin
   cbegin  returns an iterator to the beginning of a container or array
   \fI(C++11)\fP \fI(function template)\fP
   \fI(C++14)\fP
